
/**********************************************************************************\
** 文件名称: RTC.c
** 创建人员: YCG
** 创建日期: 2019-05-07
** 文档描述: 
** 版本代号: V0.1
** 版本说明: 初始版本
\********************************************************************************/
 #include "RTC.h"
 #include "MessageOut.h"
 
extern RTC_HandleTypeDef hrtc;
extern uint8_t yBuf [MessageBuf_OnceSize];

RTC_TimeTypeDef yTime = {0};	
RTC_DateTypeDef yDate = {0};

#define TimeHighToChar(yTimeH) (uint8_t)(((yTimeH>>4)&0x0F)+'0')
#define TimeLowToChar(yTimeL)  (uint8_t)((yTimeL&0x0F)+'0')


/*******************************************************************************
** 函数名称: RTC_GetTime
** 功能描述: 
** 参数说明: None
** 返回说明: None
** 创建人员: YCG
** 创建日期: 2019-05-07
********************************************************************************/
void RTC_GetTime(uint8_t* yBuf) {
	  uint8_t num=0;
	
    HAL_RTC_GetTime(&hrtc, &yTime, RTC_FORMAT_BCD);
    HAL_RTC_GetDate(&hrtc, &yDate, RTC_FORMAT_BCD);

	  yBuf[num++]=(uint8_t)'2';	
	  yBuf[num++]=(uint8_t)'0';	
	  yBuf[num++]=TimeHighToChar(yDate.Year);
	  yBuf[num++]=TimeLowToChar(yDate.Year);
	  yBuf[num++]=(uint8_t)'-';	
	  yBuf[num++]=TimeHighToChar(yDate.Month);
	  yBuf[num++]=TimeLowToChar(yDate.Month);
	  yBuf[num++]=(uint8_t)'-';	
	  yBuf[num++]=TimeHighToChar(yDate.Date);
	  yBuf[num++]=TimeLowToChar(yDate.Date);
	  yBuf[num++]=(uint8_t)' ';	

	  yBuf[num++]=TimeHighToChar(yTime.Hours);
	  yBuf[num++]=TimeLowToChar(yTime.Hours);
	  yBuf[num++]=(uint8_t)':';	
	  yBuf[num++]=TimeHighToChar(yTime.Minutes);
	  yBuf[num++]=TimeLowToChar(yTime.Minutes);
	  yBuf[num++]=(uint8_t)':';	
	  yBuf[num++]=TimeHighToChar(yTime.Seconds);
	  yBuf[num++]=TimeLowToChar(yTime.Seconds);
	  yBuf[num]=(uint8_t)' ';	
		
}

/*******************************************************************************
** 函数名称: RTC_SetTime
** 功能描述: 时间设置
** 参数说明: yHours: [输入/出] 
**			     yMinutes: [输入/出] 
** 返回说明: None
** 创建人员: YCG
** 创建日期: 2019-05-07
********************************************************************************/
void RTC_SetTime(uint8_t yHours, uint8_t yMinutes) 
{
    RTC_TimeTypeDef yTime = {0};
    yTime.Hours = yHours;
    yTime.Minutes = yMinutes;
    yTime.Seconds = 0;
    yTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
    yTime.StoreOperation = RTC_STOREOPERATION_RESET;
    yTime.TimeFormat = RTC_FORMAT_BCD;
    HAL_RTC_SetTime(&hrtc, &yTime, RTC_FORMAT_BIN);
}
//  sTime.Hours = 0x0;
//  sTime.Minutes = 0x0;
//  sTime.Seconds = 0x0;
//  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
//  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
//  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
//  {
//    Error_Handler();
//  }
//  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
//  sDate.Month = RTC_MONTH_JANUARY;
//  sDate.Date = 0x1;
//  sDate.Year = 0x0;

//  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
//  {
//    Error_Handler();
//  }
/********************************End of File************************************/

